package MountainMq.dao;


import MountainMq.po.TransMessagePO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

// mybatis的注解
@Mapper
// springBoot的注解 加上就IDEA对dao会有比较好的提示
@Repository
public interface TransMessageDao {

    //=====================硬删除版本=====================
    @Insert("INSERT INTO trans_message (id, type, service, " +
            "exchange, routing_key, queue, sequence, payload," +
            "date) " +
            "VALUES(#{id}, #{type}, #{service},#{exchange}," +
            "#{routingKey},#{queue},#{sequence}, #{payload},#{date})")
    void insert(TransMessagePO transMessagePO);

    @Update("UPDATE trans_message set type=#{type}, " +
            "service=#{service}, exchange =#{exchange},"+
            "routing_key =#{routingKey}, queue =#{queue}, " +
            "sequence =#{sequence}, payload =#{payload}, " +
            "date =#{date} " +
            "where id=#{id} and service=#{service}")
    void update(TransMessagePO transMessagePO);

    @Select("SELECT id, type, service, exchange, " +
            "routing_key routingKey, queue, sequence, " +
            "payload, date " +
            "FROM trans_message " +
            "where id=#{id} and service=#{service}")
    TransMessagePO selectByIdAndService(@Param("id") String id,
                                        @Param("service") String service);

    @Select("SELECT id, type, service, exchange, " +
            "routing_key routingKey, queue, sequence, " +
            "payload, date " +
            "FROM trans_message " +
            "WHERE type = #{type} and service = #{service}")
    List<TransMessagePO> selectByTypeAndService(
            @Param("type")String type,
            @Param("service")String service);

    @Delete("DELETE FROM trans_message " +
            "where id=#{id} and service=#{service}")
    void delete(@Param("id") String id,
                @Param("service") String service);
    //=====================硬删除版本=====================


    //=====================软删除版本=====================
//    @Insert("INSERT INTO trans_message (id, type, service, " +
//            "exchange, routing_key, queue, sequence, payload," +
//            "date,is_del) " +
//            "VALUES(#{id}, #{type}, #{service},#{exchange}," +
//            "#{routingKey},#{queue},#{sequence}, #{payload},#{date},0)")
//    void insert(TransMessagePO transMessagePO);
//
//    @Update("UPDATE trans_message set type=#{type}, " +
//            "service=#{service}, exchange =#{exchange},"+
//            "routing_key =#{routingKey}, queue =#{queue}, " +
//            "sequence =#{sequence}, payload =#{payload}, " +
//            "date =#{date} " +
//            "where id=#{id} and service=#{service}")
//    void update(TransMessagePO transMessagePO);
//
//    @Select("SELECT id, type, service, exchange, " +
//            "routing_key routingKey, queue, sequence, " +
//            "payload, date " +
//            "FROM trans_message " +
//            "where id=#{id} and service=#{service} and is_del=0")
//    TransMessagePO selectByIdAndService(@Param("id") String id,
//                                        @Param("service") String service);
//
//    @Select("SELECT id, type, service, exchange, " +
//            "routing_key routingKey, queue, sequence, " +
//            "payload, date " +
//            "FROM trans_message " +
//            "WHERE type = #{type} and service = #{service} and is_del=0")
//    List<TransMessagePO> selectByTypeAndService(
//            @Param("type")String type,
//            @Param("service")String service);
//
//    @Delete("update trans_message set is_del=1 " +
//            "where id=#{id} and service=#{service}")
//    void delete(@Param("id") String id,
//                @Param("service") String service);
    //=====================软删除版本=====================
}
